home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / N-P / OOP for C.sit / OIC.ƒ / box.c next >
Encoding:
C/C++ Source or Header  |  1988-12-09  |  1.4 KB  |  92 lines  |  [TEXT/KAHL]

  1. /*
  2.  *            simple box class for the Objects-in-C tester
  3.  *
  4.  *            Copyright © John Wainwright 1988
  5.  *
  6.  */
  7.  
  8. #include "oic.h"
  9. #include "generics.h"
  10.  
  11. typedef struct                    /* box IV's                                    */
  12. {
  13.     object    tl;
  14.     object    br;
  15. } box_i;
  16. typedef object box;
  17.  
  18. class    Box;
  19.  
  20. defGeneric(offset,     offsetGeneric,     "offset")
  21.  
  22. /* ------------------------------ Box Ops -------------------------------- */
  23.  
  24. static box
  25. _new(self, b, ap)
  26.     box        self;
  27.     box_i    *b;
  28.     struct
  29.     {
  30.         double    top;
  31.         double    left;
  32.         double    bottom;
  33.         double    right;
  34.     } *ap;
  35. {
  36.     extern class    Coord;
  37.     
  38.     b->tl = New(Coord, ap->left, ap->top);
  39.     b->br = New(Coord, ap->right, ap->bottom);
  40.     return Super(self);
  41. }
  42.  
  43. static box
  44. _offset(self, b, args)
  45.     box        self;
  46.     box_i    *b;
  47.     struct {double dx; int dy;} *args;
  48. {
  49.     offset(b->tl, args->dx, args->dy);
  50.     offset(b->br, args->dx, args->dy);
  51. }
  52.  
  53. static box
  54. _draw(self, b)
  55.     box        self;
  56.     box_i    *b;
  57. {
  58.     Rect     r;
  59.     
  60.     r.top = yCoord(b->tl);
  61.     r.left = xCoord(b->tl);
  62.     r.bottom = yCoord(b->br);
  63.     r.right = xCoord(b->br);
  64.  
  65.     FrameRect(&r);
  66. }
  67.  
  68. static string
  69. _replist(self, b)
  70.     box        self;
  71.     box_i     *b;
  72. {
  73.     register replist    replist;
  74.  
  75.     replist = New(Replist, "{", "}", ".");
  76.     add(replist, repList(b->tl), repList(b->br), END);
  77.     return replist;
  78. }
  79.  
  80. /*------------------------------ Init Classes --------------------------------*/
  81.  
  82. InitBoxClass()
  83. {
  84.     Box = NewClass(sizeof(box_i), 0, "Box", IndexMixin, END);
  85.     AddMethods(Box,
  86.         newGeneric,            _new,
  87.         drawGeneric,        _draw,
  88.         offsetGeneric,        _offset,
  89.         repListGeneric,        _replist,    
  90.         END);
  91. }
  92.